<?php

namespace app\admin\model;

use think\Model;

class QuestionsCategory extends Model
{
    protected $autoWriteTimestamp = true;

    public static function getList()
    {
        $where = [];
        $limit = input('get.limit');
        if (input('get.title')) {
            $where[] = ['title', 'like', "%" . input('get.title') . "%"];
        }
        if (input('get.status')) $where[] = ['status', '=', input('get.status') - 1];
        $list = self::order('id', 'desc')
            ->where($where)
            ->paginate($limit);
        return ['code' => 0, 'data' => $list->items(), 'extend' => ['count' => $list->total(), 'limit' => $limit]];
    }

    public static function getCategoryAll()
    {
        return self::order('id', 'desc')
            ->where('status', '=', 1)
            ->field('id, title')
            ->select()
            ->toArray();
    }

    public static function getCategoryByIds($ids)
    {
        return self::whereIn('id', $ids)
            ->field('id,title')
            ->select()
            ->toArray();
    }
}